/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.farent.solutions.plugins.stripes.hyperstripes.utils;

import java.lang.reflect.Field;
import java.util.Collection;
import net.sourceforge.stripes.util.ReflectUtil;

/**
 *
 * @author user
 */
public class Utils {

    public static final String EMPTY_STRING = "";

    public static boolean nullOREmpty(Object obj) {
        if (obj == null) {
            return true;
        } else if (obj instanceof Collection) {
            Collection col = (Collection) obj;
            return col.isEmpty();
        } else if (obj instanceof String) {
            String str = (String) obj;
            return str.isEmpty();
        }
        return false;
    }

    public static boolean assignIfhasOwnProperty(Object obj, String feildName, Object fieldValue) {
        Field field = ReflectUtil.getField(obj.getClass(), feildName);
        try {
            if (field != null) {
                field.set(feildName, fieldValue);
                return true;
            }
        } catch (Exception e) {}
        return false;
    }
}
